package com.qf.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitOrderCancelPayConfig {

    @Bean("payQueue")
    public Queue payQueue(){
        return new Queue("pay-queue");
    }

    @Bean("payDeadQueue")
    public Queue payDeadQueue(){

        Map map = new HashMap<>();
        map.put("x-dead-letter-exchange","pay-exchange");
        map.put("x-dead-letter-routing-key","pay");

        return new Queue("pay-dead-queue",true,false,false,map);
    }

    @Bean("payExchange")
    public DirectExchange directExchange(){
        return new DirectExchange("pay-exchange");
    }
    @Bean("payDeadExchange")
    public DirectExchange directDeadExchange(){
        return new DirectExchange("pay-dead-exchange");
    }

    @Bean
    Binding bindPayQueueToPayExchange(@Qualifier("payQueue")Queue queue,@Qualifier("payExchange")DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with("pay");
    }

    @Bean
    Binding bindDeadPayQueueToDeadPayExchange(@Qualifier("payDeadQueue")Queue queue,@Qualifier("payDeadExchange")DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with("deadpay");
    }
}
